import pytest
from pywinauto import Application

from Logger import Log


class music_info():
    def __init__(self):
        self.app = None
        self.win = None
        self.log = Log.logconf()
        self.path = "D:\\hewtao\\test-development-master\\qqmusic\\QQMusic.exe" #workpath
        #self.path = "D:\\BIT\\test\\GUITest\\qqmusic\\QQMusic.exe" #testpath


    def start(self):
        try:
            #self.app = Application(backend="uia").start(self.path)
            self.app = Application(backend="uia").connect(process=33120)
            self.win = self.app.window(title="QQMusic")
            self.win.wait("visible")
            # self.win.print_control_identifiers()
            self.log.info("程序启动成功")
        except Exception as e:
            self.log.error(f"程序启动失败：{e}")

    def stop(self):
        if self.win:
            self.win.close()

@pytest.fixture(scope="session")
def music_app():
    music = music_info()
    music.start()
    yield music
    # music.stop()

